﻿using System.Collections.Generic;
using System.Linq;
using NHibernate;
using NHibernate.Linq;
using Noodles.Core.Model;

namespace Noodles.Core.Repositories
{
    public class AdminRepository : IAdminRepository
    {
        private readonly ISession session;

        public AdminRepository(ISession session)
        {
            this.session = session;
        }

        public IQueryable<Setting> GetSettings()
        {
            return session.Query<Setting>();
        }

        public void UpdateCommentCountFor(int entryId)
        {
            //var commentCount = session
            //    .QueryOver<Comments>()
            //    .Where(c => c.Entry.Id == entryId && c.Status == 1)
            //    .ToRowCountQuery()
            //    .SingleOrDefault<int>(); 

            //var entry = session.Get<Entry>(entryId);
            //entry.CommentCount = commentCount;
            //session.Flush();
        }

        public void Save(IEnumerable<Setting> settings)
        {
            foreach (var setting in settings)
            {
                session.SaveOrUpdate(setting);
            }
            session.Flush();
        }
    }
}
